"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/10/27 8:35
@Description : 字符串类型数据的常见操作

"""

str_info = "hello world"
# 遍历字符串
for char in str_info:
    print(char)

print("--------------------------------")
# 索引操作
# sub_str = str_info[0]
sub_str = str_info[-1]
print(sub_str)

print("--------------------------------")
str_len = len(str_info)

for i in range(str_len):
    print(str_info[i])

# 字符串切片
print("---------------------------------")
# sub_str = str_info[0:5]
# sub_str = str_info[:5]
# sub_str = str_info[1:]
# sub_str = str_info[0:5:2]
sub_str = str_info[-5:]
print(sub_str)
print("---------------------------------")
#  + 组合    * 重复
str1 = 'hello'
str2 = 'world'
print(str1 + str2)
str3 = "*"
print(str3 * 10)
print("---------------------------------")
str_info = "Hello world"
print(f'str_info id = {id(str_info)}')
str_index = str_info.index('H')
print('h in hello index = {}'.format(str_index))

#  返回指定字符在字符串中第一次出现的位置
str_index = str_info.index('l', 4)
print('l in hello index = {}'.format(str_index))

char_num = str_info.count('l')
print('l in hello count = {}'.format(char_num))

# 字符串不可被改变 如果对你字符串修改操作  会返回新的字符串 原字符串不会改变
print("---------------------------------")
#  转大写
upper_str = str_info.upper()
print('upper  hello world  = {}'.format(upper_str))
print(f'{str_info}str_info id = {id(str_info)}')
# 转小写
lower_str = str_info.lower()
print('lower  hello world = {}'.format(lower_str))
# 搜字母大写
title_info = str_info.title()
print('title  hello world = {}'.format(title_info))

print("---------------------------------")
# 判定字符串的开始 结尾   区分大小写
start_with = str_info.startswith('h')
print('start with Hello world = {}'.format(start_with))
end_with = str_info.endswith('l')
print('end with Hello world = {}'.format(end_with))

print("---------------------------------")
# 判定字符串是不是符合要求
is_lower = str_info.islower()
print('is_lower  Hello world = {}'.format(is_lower))
upper_str = str_info.upper()
is_upper = upper_str.isupper()
print('is_upper  {} = {}'.format(upper_str, is_upper))

print("---------------------------------")
new_str = " hello world "
# 去除字符串中的空白字符  去除字符串的前后空白
strip_str = new_str.strip()
print(new_str)
print(strip_str)
print("---------------------------------")
#  字符串的分割  批量删除    delete  from  student where  id  in (1,2,3)  前端  "1,2,3,4,5"
num_str = "1,2,3,4,5"
numbers_list = num_str.split(',')
print(numbers_list,type(numbers_list))
